import React from "react";
import { WeaSearchGroup,WeaFormItem, WeaLocaleProvider } from 'ecCom';
import {WeaSwitch} from 'comsMobx';
import { Button } from 'antd';

const getLabel = WeaLocaleProvider.getLabel;

class Condition extends React.Component{
    render(){
        const { requestLogParams = {}, searchForm } = this.props.logListStore;
        const {logCondition = []} =requestLogParams;
        const {isFormInit} = searchForm;
        let group = [];
        const formParams = searchForm.getFormParams();
        isFormInit && logCondition.map((c,ecindex) =>{
            let items = [];
            c.items.map(fields => {
                const domKey = typeof fields.domkey === "object" ? fields.domkey[0] : fields.domkey;
                items.push({
                    com:(<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@id9pm3@${domKey}`}
                        label={`${fields.label}`}
                        labelCol={{span: `${fields.labelcol}`}}
                        wrapperCol={{span: `${fields.fieldcol}`}}>
                        <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@9yqo5o@${domKey}`} fieldConfig={fields} form={searchForm} formParams={formParams}/>
                    </WeaFormItem>),
                    colSpan:1
                })
            });
            group.push(<WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@z3f5it@${ecindex}`} needTigger={true} title={c.title} showGroup={c.defaultshow} items={items}/>)
        });
        return <div>{group}</div>;
    }
}

const getAdButtons = (logListStore) => {
    const {advanceSearch,controllSearchDrop,clearFormFields} = logListStore;
    return [
        (<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@0lu3bi@search`} type="primary" onClick={()=>{advanceSearch();controllSearchDrop(false);}}>{getLabel(197, '搜索')}</Button>),
        (<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@8t3r64@reset`} type="ghost" onClick={()=>{clearFormFields()}}>{getLabel(2022, '重置')}</Button>),
        (<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@ag6dk2@cancel`} type="ghost" onClick={()=>{controllSearchDrop(false)}}>{getLabel(31129,'取消')}</Button>)
    ];
}

export {Condition,getAdButtons}
